package com.exject.android.socialphonebook;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

import com.exject.android.socialphonebook.view.ActionsListActivity;
import com.exject.android.socialphonebook.view.ContactsListActivity;
import com.exject.android.socialphonebook.view.FavoriteListActivity;
import com.exject.android.socialphonebook.view.NewContactActivity;
import com.exject.android.socialphonebook.view.OthersListActivity;
import com.exject.android.socialphonebook.view.SettingsActivity;

public class PhonebookActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);
        Resources res = getResources();
        TabHost mTabHost = getTabHost();
        /*
         * mTabHost.addTab(mTabHost.newTabSpec("one").setIndicator("ceveni")
         * .setContent(new Intent(this, Sz_dPush.class)));
         */
        mTabHost.addTab(mTabHost.newTabSpec("one").setIndicator("Favoriten", res.getDrawable(R.drawable.favorite_active))
                .setContent(new Intent(this, FavoriteListActivity.class)));
        mTabHost.addTab(mTabHost.newTabSpec("two").setIndicator("Actions", res.getDrawable(R.drawable.actions_active))
                .setContent(new Intent(this, ActionsListActivity.class)));
        mTabHost.addTab(mTabHost.newTabSpec("three").setIndicator("Contacts", res.getDrawable(R.drawable.contacts_active))
                .setContent(new Intent(this, ContactsListActivity.class)));
        mTabHost.addTab(mTabHost.newTabSpec("four").setIndicator("Others", res.getDrawable(R.drawable.others_active))
                .setContent(new Intent(this, OthersListActivity.class)));
        mTabHost.setCurrentTab(0);
    }
    
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.contact_list_menu, menu);
        return true;
    }
    
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.contactListMenuNewContact:
            menuNewContact();
            return true;
        case R.id.contactListMenuPreferences:
            menuPreferences();
            return true;
        case R.id.contactListMenuSearch:
            menuSearch();
            return true;
        case R.id.contactListMenuQuit:
            this.finish();
            return true;
        default:
            return super.onContextItemSelected(item);
        }
    }
    
    private void menuSearch() {
        // TODO Auto-generated method stub
        
    }
    
    private void menuPreferences() {
        Intent i = new Intent(this, SettingsActivity.class);
        this.startActivity(i);
    }
    
    
    private void menuNewContact() {
        Intent newContactIntent = new Intent(this, NewContactActivity.class);
        this.startActivity(newContactIntent);
    }
}
